home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
pctj8410.arc
/
MYSUBS.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-09-14
|
3KB
|
98 lines
PAGE 58,132
TITLE MYSUBS -- example BASIC-callable subroutine image
NAME MYSUBS
COMMENT *
This program may be freely copied and distributed. The author
assumes no responsibility for its use or reliability.
This program defines the dispatch table and entry points for
BASIC-callable subroutines. The subroutine image is created
with the following commands:
MASM MYSUBS,MYSUBS,MYSUBS;
LINK MYSUBS,,;
Written 4/15/84 by Ron Bauman
*
;
CSEG SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:CSEG
;
DATA SEGMENT WORD PUBLIC 'DATA'
;
; define message strings
;
ERRMSG DB ' Invalid subroutine call.',13,10,'$'
MSG1 DB ' Subroutine 1 executed.',13,10,'$'
MSG2 DB ' Subroutine 2 executed.',13,10,'$'
;
DATA ENDS
;
; Define the dispatch table. The order of entries in this table must
; correspond exactly with the order of name offset definitions in the
; user's BASIC program. Note that it must appear at location 0 in the
; subroutine image. This also means its segment must be defined first
; to the linker.
;
MAIN PROC NEAR
;
JMP NEAR PTR CALLERR
;error entry. catches improperly defined
;offsets in user's program.
JMP NEAR PTR SUB1
JMP NEAR PTR SUB2
;
MAIN ENDP
;
; CALLable subroutines definition
;
SUB1 PROC FAR ;subroutine 1
;
PUSH DS ;save BASIC's data space address
MOV AX,SEG DATA ;get our data segment
MOV DS,AX
ASSUME DS:DATA
MOV DX,OFFSET MSG1 ;set up pointer to message 1
MOV AH,9H ;print the string to standard output
INT 21H
POP DS
RET
SUB1 ENDP
;
SUB2 PROC FAR ;subroutine 2
;
PUSH DS ;save BASIC's data space address
MOV AX,SEG DATA ;get our data segment
MOV DS,AX
ASSUME DS:DATA
MOV DX,OFFSET MSG2 ;set up pointer to message 2
MOV AH,9H ;print the string to standard output
INT 21H
POP DS
RET
SUB2 ENDP
;
; The following routine catches calls to this image with an incorrectly
; assigned offset. The usual case is that the user has mistyped the
; subroutine name, BASIC thought it was a new variable and assigned
; zero to it.
;
CALLERR PROC FAR ;subroutine 1
;
PUSH DS ;save BASIC's data space address
MOV AX,SEG DATA ;get our data segment
MOV DS,AX
ASSUME DS:DATA
MOV DX,OFFSET ERRMSG
;set up pointer to our message
MOV AH,9H ;print the string to standard output
INT 21H
POP DS
RET
CALLERR ENDP
;
CSEG ENDS
END